﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //连接字符串
            string ConnStr = "server = .;database=hong;uid=sa;Pwd=wang20010109";
            //声明连接对象
            SqlConnection sqlconn = new SqlConnection(ConnStr);
            //打开连接
            sqlconn.Open();
            //声明sql指令
            string sql = "select * from Student2";
            //声明指令对象
            SqlCommand sqlcm = new SqlCommand(sql, sqlconn);
            SqlDataReader sqldr = sqlcm.ExecuteReader();
            while (sqldr.Read())
            {
                varchar studentname = (varchar)sqldr["studentname"];
                int no = (int)sqldr["no"];
                char sex = (char)sqldr["sex"];
                Console.WriteLine("学生名字\t" + studentname + "\t学生编号\t" + sex + "\t性别\t");
            }
        }
    }
}
